package se.webbzon.boltzmann.minigame.page;

import java.awt.Dimension;
import java.awt.Font;

import se.webbzon.boltzmann.configuration.Graphics;
import se.webbzon.boltzmann.hud.AbstractHudLayout;
import se.webbzon.boltzmann.resource.Resources;

public class DefaultPageLayout extends AbstractHudLayout implements PageLayout {
	
	// The fonts of this layout
	private final Font plain, bold, italic, boldItalic;
	
	// The maximal number of characters per line using the default font size
	private final int lineMaxLength;
	
	// The default font size
	private final float fontSize;
	
	// The default image size
	private final Dimension imgSize;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public DefaultPageLayout() {
		plain = Resources.getFont("texgyrecursor_plain");
		bold = Resources.getFont("texgyrecursor_bold");
		italic = Resources.getFont("texgyrecursor_italic");
		boldItalic = Resources.getFont("texgyrecursor_bold_italic");
		switch (Graphics.instance().getResolution()) {
		case HIGH:
			fontSize = 16;
			lineMaxLength = 124;
			imgSize = new Dimension(256,256);
			break;
		case MEDIUM:
			fontSize = 16;
			lineMaxLength = 93;
			imgSize = new Dimension(192,192);
			break;
		default:
			fontSize = 16;
			lineMaxLength = 62;
			imgSize = new Dimension(128,128);
		}
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public Font getFont(int level, boolean bold, boolean italic) {
		final float size = fontSize * (1 + 0.25f * level);
		if (bold) {
			if (italic)
				return boldItalic.deriveFont(size);
			else
				return this.bold.deriveFont(size);
		} else if (italic)
			return this.italic.deriveFont(size);
		else
			return plain.deriveFont(size);
	}

	@Override public int getLineMaxLength() {
		return lineMaxLength;
	}

	@Override public int getLineSpacing() {
		return 4;
	}
	
	@Override public int getItemSpacing() {
		return 16;
	}

	@Override public int getImageWidth() {
		return imgSize.width;
	}

	@Override public int getImageHeight() {
		return imgSize.height;
	}	

}
